﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Cn.Edwon.Web.Support;
using Cn.Cellula.Model.Oms;
using System.Collections.Generic;
using Cn.Edwon.Spring;
using Cn.Cellula.Biz.Port;
using Cn.Cellula.Client;
using Cn.Cellula.Model.Product;

namespace Cn.Cellula.Website.Ws {
    public partial class _Product : PageSupport {
        String Act = "";
        
        protected void Page_Load(object sender, EventArgs e) {
            Act = Request.QueryString["act"];
        }

        private void ResponseResult(String content) {
            Response.Clear();
            Response.Write(content);
        }

        private void DoAction() {
            if (Act == "follow") {
                DoFollow();
            }
        }
        /// <summary>
        /// 关注一个产品
        /// </summary>
        private void DoFollow() {
            if (!this.Ac.IsLogined) {
                this.ResponseResult("请先登录");
                return;
            }
            IOmsBiz biz = BizFactory.Get<IOmsBiz>();
            String productKey = Request.QueryString["pid"];
            if (String.IsNullOrEmpty(productKey)) {
                this.ResponseResult("缺少产品参数");
                return;
            }
            TOmsProductFollowEO eo = new TOmsProductFollowEO();
            eo.FollowDate = DateTime.Now;
            eo.FollowDesc = "";
            eo.OwnerKey = this.OwnerKey;
            eo.ProductKey = productKey;
            try {
                TProductEO peo = biz.Load<TProductEO>(productKey);
                eo.ProductRemark = peo.ProductName;
            } catch (Exception ex) {
                log.Error(ex.Message);
                this.ResponseResult("获取产品数据错误");
                return;
            }
            try {
                biz.Save<TOmsProductFollowEO>(eo);
            } catch (Exception ex) {
                this.ResponseResult("保存数据错误："+ClientBiz.EncodeJsString(ex.Message));
                return;
            }
            this.ResponseResult("");
        }
    }
}
